package com.study.zzedu.ui.schoolroll;

import android.content.Context;
import android.content.Intent;
import android.support.v4.content.LocalBroadcastManager;

import com.study.zzedu.base.BaseModel;
import com.study.zzedu.http.OnResultListener;
import com.study.zzedu.utils.AppConstant;
import com.study.zzedu.utils.LogUtil;
import com.study.zzedu.utils.OkHttpUtils;

import org.json.JSONObject;

import java.io.IOException;

public class SchoolRollModel extends BaseModel {

    public void getUserDetailMessage(final Context context, final OnResultListener resultListener) {

        OkHttpUtils.getInstance(context).getJsonForString(OkHttpUtils.BASE_URL + "/appAccount/getUserDetailMessage",
                new String[]{"userCode"}, new String[]{AppConstant.userCode}, new OkHttpUtils.HttpCallBack() {
                    @Override
                    public void onSuccess(String obj) {
                        try {
                            JSONObject jObject = new JSONObject(obj);

                            if (0 == jObject.getInt("code")) {
                                LogUtil.e("Forget", "查询学籍信息成功");
                                resultListener.onSuccess(obj);
                            } else {
                                LogUtil.e("Forget", "查询学籍信息失败");
                                resultListener.onError(jObject.get("message").toString());
                            }
                        } catch (Exception e) {
                            e.toString();
                        }
                    }

                    @Override
                    public void onSuccess(JSONObject obj) {
                        //resultListener.onSuccess(obj.toString());
                    }

                    @Override
                    public void onError(String msg) {
                        LogUtil.e("Forget", "查询学籍信息失败");
                        resultListener.onError(msg);
                    }
                });
    }

    public void getUserScoreList(Context context, final OnResultListener resultListener){

        OkHttpUtils.getInstance(context).getJsonForString(OkHttpUtils.BASE_URL + "/appAccount/getUserScoreList",
                new String[]{"userCode"}, new String[]{AppConstant.userCode}, new OkHttpUtils.HttpCallBack() {
                    @Override
                    public void onSuccess(String obj) {
                        try {
                            JSONObject jObject = new JSONObject(obj);
                            if (0 == jObject.getInt("code")) {
                                LogUtil.e("Forget", "查询成绩信息成功");
                                resultListener.onSuccess(obj);
                            } else {
                                LogUtil.e("Forget", "查询成绩信息失败");
                                resultListener.onError(jObject.get("message").toString());
                            }
                        } catch (Exception e) {
                            e.toString();
                        }
                    }

                    @Override
                    public void onSuccess(JSONObject obj) {
                        //resultListener.onSuccess(obj.toString());
                    }

                    @Override
                    public void onError(String msg) {
                        LogUtil.e("Forget", "查询成绩信息失败");
                        resultListener.onError(msg);
                    }
                });
    }
}
